/**
 * @file   PacketParser.h
 * @author Djuro Drljaca (djurodrljaca@gmail.com)
 * @date   2014-04-21
 * @brief  DON packet parser object.
 *
 * Copyright 2014  Djuro Drljaca (djurodrljaca@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef DON_CORE_PACKET_PACKETPARSER_H
#define DON_CORE_PACKET_PACKETPARSER_H

#include <DON/Core/Packet/PacketHeader.h>
#include <DON/Core/Packet/GenericPacket.h>

namespace DON
{
namespace Core
{
namespace Packet
{

/**
 * @brief The PacketParser class
 */
class LIBDONQT4CORESHARED_EXPORT PacketParser
{
public:
    /**
     * @brief Constructor
     */
    PacketParser();

    /**
     * @brief Destructor
     */
    ~PacketParser();

    /**
     * @brief Add data to the parser
     * @param data Data
     *
     * The data will be saved in a buffer until it is processed by the parser.
     */
    void addData(const QByteArray &data);

    /**
     * @brief Parse data
     */
    void parseData();

    /**
     * @brief Checks if at least one packet is available
     * @retval true At least one packet is available
     * @retval false No packets are available
     */
    bool packetsAvailable() const;

    /**
     * @brief Take packet
     * @param[out] ok Error status output (true --> success, false --> error)
     * @return Packet
     */
    GenericPacket takePacket(bool *ok = NULL);

private:
    class Private;
    Private *d;
};

}
}
}

#endif // DON_CORE_PACKET_PACKETPARSER_H
